package cn.java.lambda.test3;

import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;

/**
 * 测试构造方法引用
 * @author 攀博课堂(www.pbteach.com)
 * @version 1.0
 **/
public class TestConstructorFun {

    public static void main(String[] args) {
        test2();

    }

    //无参构造方法引用
    public static void test1(){
        //引用PbStudent类型的无参构造方法
        Supplier<PbStudent> fun =  PbStudent::new;
        //创建学生对象
        PbStudent pbStudent = fun.get();
        System.out.println(pbStudent);
    }


    //有参构造方法引用
    public static void test2(){
        //引用PbStudeng类型下的pbstudent(String nickname)构造方法。
        Function<String,PbStudent> fun = PbStudent::new;
        //通过方法引用调用有参构造方法
        PbStudent pbStudent = fun.apply("www.pbteach.com");
        System.out.println("昵称："+pbStudent.getNickname());

        //引用PbStudeng类型下的PbStudent(String id,String nickName)
        BiFunction<String,String,PbStudent> fun2 = PbStudent::new;
        PbStudent pbStudent1 = fun2.apply("100", "攀博课堂");
        System.out.println(pbStudent1.getId()+"  "+pbStudent1.getNickname());

    }
}
